const Router = require("koa-router");

const {
  userValidator,
  verifyUser,
  cryptPassword,
  verifyLogin,
} = require("../middleware/user.middleware");

const { auth } = require("../middleware/auth.middleware");

const {
  register,
  login,
  changePassword,
  editUserInfo,
} = require("../controller/user.controller");

const {
  collectTopic,
  deleteCollect,
  getAllCollects,
} = require("../controller/collect.controller");

const router = new Router({ prefix: "/users" });

//? GET '/users/'
/* router.get("/", (ctx, next) => {
  ctx.body = "hello users";
}); */

//!注册接口
router.post("/register", userValidator, verifyUser, cryptPassword, register);

//! 登录接口
router.post("/login", userValidator, verifyLogin, login);

//! 修改密码接口
/* router.patch("/", auth, cryptPassword, (ctx, next) => {
  console.log(ctx.state.user);
  ctx.body = "修改密码成功";
}); */
router.patch("/", auth, cryptPassword, changePassword);

router.post("/edit_info", auth, editUserInfo);

router.post("/collect_topic", auth, collectTopic);
router.post("/delete_collect_topic", auth, deleteCollect);

router.post("/get_user_collects", auth, getAllCollects);

//* router.post("/get_my_topics", auth, getMyTopics); */

module.exports = router;
